﻿var dom = fl.getDocumentDOM();
var lib = dom.library;

if( dom.selection.length == 0 )
{
	alert( "Please make a selection on the page." );
}
else if( dom.selection.length >1 )
{
	alert( "You can only select one item to find in the library. Deselect and try again." );
}
else
{
	
	var item = dom.selection[ 0 ];
	var libraryname = item.libraryItem.name;
	var folders = libraryname.split( "/" );
	var folderpath = "";
	
	for( var i=0; i<folders.length-1; i++ )
	{
		if( i == 0 ) folderpath = folders[ i ];
		else folderpath += "/" +folders[ i ];
		fl.trace( folderpath );
		lib.expandFolder( true, false, folderpath )
	}
	lib.selectItem( libraryname );
	lib.updateItem( libraryname );

}
